﻿<script type="text/javascript">
    var familymemberWidgetRequestSend = function(action, user_id, notification_id)
    {
      var url;
      if( action == 'confirm' )
      {
        url = '<?php echo $this->url(array('module' => 'familymember', 'controller' => 'index', 'action' => 'confirm'), 'default', true) ?>';
      }
      else if( action == 'reject' )
      {
        url = '<?php echo $this->url(array('module' => 'familymember', 'controller' => 'index', 'action' => 'reject'), 'default', true) ?>';
      }
      else
      {
        return false;
      }
      
      (new Request.JSON({
        'url' : url,
        'data' : {
          'user_id' : user_id,
          'format' : 'json',
          'type' : document.getElementById('familyMemberType').value
        },
        'onSuccess' : function(responseJSON)
        {
          if( !responseJSON.status )
          {
            $('familymember-widget-request-' + notification_id).innerHTML = responseJSON.error;
          }
          else
          {
            $('familymember-widget-request-' + notification_id).innerHTML = responseJSON.message;
          }
        }
      })).send();
    }
</script>

<li id="familymember-widget-request-<?php echo $this->notification->notification_id ?>">
  <?php echo $this->itemPhoto($this->notification->getSubject(), 'thumb.icon') ?>
  <div>
    <div>
      <?php echo $this->translate('%1$s 添加你为他(她)的 '.$this->type, $this->htmlLink($this->notification->getSubject()->getHref(), $this->notification->getSubject()->getTitle())); ?>
    </div>
    <div>
        <select name="type" id="familyMemberType">
            <?php foreach ( $this->types as $type ){
                echo '<option value="'.$type->type_id.'">'.$type->title.'</option>';
            } ?>
        </select>
        <button type="submit" onclick='familymemberWidgetRequestSend("confirm", <?php echo  $this->string()->escapeJavascript($this->notification->getSubject()->getIdentity()) ?>, <?php echo $this->notification->notification_id ?>)'>
          <?php echo $this->translate('同意加入');?>
        </button>
        <?php echo $this->translate('或');?>
        <a href="javascript:void(0);" onclick='familymemberWidgetRequestSend("reject", <?php echo $this->string()->escapeJavascript($this->notification->getSubject()->getIdentity()) ?>, <?php echo $this->notification->notification_id ?>)'>
          <?php echo $this->translate('忽略请求');?>
        </a>
    </div>
  </div>
</li>